package com.yisu.expressway.manager.core.service.impl;

import com.yisu.expressway.ewf.entity.DataAnalusisGoods;
import com.yisu.expressway.ewf.entity.DataAnalysisCategory;
import com.yisu.expressway.manager.core.mapper.*;
import com.yisu.expressway.manager.core.service.IDataAnalysisService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.util.List;

/**
 * Created by xlt on 2017/5/3.
 */
@Service
public class DataAnalysisServiceImpl extends BaseService implements IDataAnalysisService {
    @Resource
    private DataAnalysisCategoryMapper dataAnalysisCategoryMapper;
    @Resource
    private DataAnalusisGoodsMapper dataAnalusisGoodsMapper;
    @Resource
    private GoodsArchivesMapper goodsArchivesMapper;
    @Resource
    private GoodsSpecificationMapper goodsSpecificationMapper;
    @Resource
    private SpecificationGoodsMapper specificationGoodsMapper;

    @Override
    public boolean addDataAnalysisCategory(DataAnalysisCategory dataAnalysisCategory) {
        return dataAnalysisCategoryMapper.insert(dataAnalysisCategory) > 0;
    }

    @Override
    public List<DataAnalysisCategory> getDataAnalysisCategoryList() {
        return dataAnalysisCategoryMapper.getDataAnalysisCategoryList();
    }

    @Override
    public boolean resetDataAnalysisCategory() {
        return dataAnalysisCategoryMapper.resetDataAnalysisCategory() > 0;
    }

    @Override
    public boolean addDataAnalusisGoods(DataAnalusisGoods dataAnalusisGoods) {
        return dataAnalusisGoodsMapper.insert(dataAnalusisGoods) > 0;
    }

    @Override
    public List<DataAnalusisGoods> getDataAnalusisGoodsList() {
        return dataAnalusisGoodsMapper.getDataAnalusisGoodsList();
    }

    @Override
    public boolean resetDataAnalusisGoods() {
        return dataAnalusisGoodsMapper.resetDataAnalusisGoods() > 0;
    }

    @Override
    public String imageUploadForAnalysis(File file) {
        if (file != null) {
            return uploadFileForLocation(file);
        }
        return "";
    }

    @Override
    public boolean resetGoodsInfo() {
        try {
            goodsArchivesMapper.resetInfo();
            goodsSpecificationMapper.resetInfo();
            specificationGoodsMapper.resetInfo();
        } catch (Exception ex) {
            return false;
        }
        return true;
    }
}
